package utils

import (
	"crypto/md5"
	"encoding/hex"
	"fmt"
	"github.com/bwmarrin/snowflake"
)

var node *snowflake.Node

func init() {
	var err error
	node, err = snowflake.NewNode(1)
	if err != nil {
		panic(fmt.Sprintf("snowflake id init err:%v", err))
	}
}

// GetSoftId 基于推特的开源雪花算法
func GetSoftId() (id int64) {
	// Generate a snowflake ID.
	id = node.Generate().Int64()
	return id
}

// MD5 返回内容的MD5字符串
func MD5(str string) string {
	bs := md5.New().Sum([]byte(str))
	return hex.EncodeToString(bs)
}
